package org.exhaust.barbecue.spring;


import java.lang.reflect.Proxy;

/**
 * 参考MapperProxyFactory
 */
public class ManagerProxyFactory {

    public static Object newInstance(Class<?> managerInterface) throws Exception {
        if (managerInterface.isInterface()) {
            return newInstanceFromInterface(managerInterface);
        }
        throw new Exception("只支持接口");
    }


    private static Object newInstanceFromInterface(Class<?> managerInterface) {
        JdkDynamicProxy proxy = new JdkDynamicProxy(managerInterface);
        return Proxy.newProxyInstance(managerInterface.getClassLoader(), new Class[]{managerInterface}, proxy);
    }

}
